package com.wasu.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.wasu.jopo.User;
import com.wasu.jopo.UserQuery;
import com.wasu.mapper.UserMapper;
import com.wasu.service.UserService;

import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.JedisCluster;

@Service
@Transactional
@Slf4j
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;
	
	@Autowired
	private JedisCluster jedisCluster;
	//缓存
	//@Cacheable("selectByPrimaryKey")  
	@Override
	public User selectByPrimaryKey(Integer id) {
		log.info("调用数据库...........");
		return userMapper.selectByPrimaryKey(id);
	}

	@Override
	public void insert(User user) {
		int id = userMapper.insert(user);
		jedisCluster.set(user.getId().toString(), user.toString());
	}

	// 缓存
	//@Cacheable("selectByExample")
	@Override
	public List<User> selectByExample(UserQuery userQuery) {
		log.info("调用数据库...........");
		return userMapper.selectByExample(userQuery);
	}

	@Override
	public String findRedis(Integer id) {
		return jedisCluster.get(id.toString());
	}

	@Override
	public void addRedis(User user) {
		jedisCluster.set(user.getId().toString(), user.getUsername());
		
	}

}
